package com.qn.config;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;

/**
 * 国际化配置
 *
 * @author QN
 * @date 2025/01/01
 */
@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class I18nConfig {

    private final DynamicMessageSource messageSource;

    @Bean
    public LocaleResolver localeResolver() {
        return new I18nLocaleResolver();
    }

    @Bean
    public LocalValidatorFactoryBean validatorFactoryBean() {
        LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
        factoryBean.afterPropertiesSet();
        factoryBean.setValidationMessageSource(messageSource);
        return factoryBean;
    }

}
